package com.briup.shopadmin.web.controller;

import com.briup.shopadmin.common.Result;
import com.briup.shopadmin.common.bean.Banner;
import com.briup.shopadmin.service.IBannerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("banner")
@Api(tags = "轮播管理相关接口")
public class BannerController {
    @Autowired
    IBannerService bannerService;

    @GetMapping("findBanners")
    @ApiOperation("分⻚查询轮播信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "title", value = "轮播标题", required = false),
            @ApiImplicitParam(name = "active", value = "轮播启用状态  传值String类型 的true 或者 false", dataType = "String", allowableValues = "true,false"),
            @ApiImplicitParam(name = "pageSize", value = "⻚面显示数据条数", required = true),
            @ApiImplicitParam(name = "pageNum", value = "⻚码", required = true)
    })
    public Result findBanners(
            @RequestParam(required = false, defaultValue = "") String title,
            @RequestParam(required = false, defaultValue = "") String active,
            Integer pageSize,
            Integer pageNum) {
        Page<Banner> page = bannerService.findAll(title, active, pageSize, pageNum);
        return Result.success(page);
    }

    @PostMapping("saveBanner")
    @ApiOperation("新增/修改轮播信息  新增不需要传递id值 但是修改是必须要有的")
    public Result saveBanner(@RequestBody Banner banner) {
        bannerService.save(banner);
        return Result.success();
    }

    @PutMapping("updateActive/{id}")
    @ApiOperation("修改轮播的启用状态")
    public  Result updateActive(@PathVariable Long id){

        bannerService.updateActive(id);
        return  Result.success();
    }
}

